#define _CRT_SECURE_NO_WARNINGS  1
#include<stdio.h>
#include<stdlib.h>
int num=0;
typedef struct list
{
    int date;
    struct list* next;
}list;
list* read(list*);
list* Splicing(list*, list*);
void sort(list*);
void print(list*);
int main()
{
    list *head1,*head2,*head3;
    head1 = NULL;
    head2 = NULL;
    head3 = NULL;
    //读入
    head1 = read(head1);
    head2 = read(head2);
    //拼接
    head3=Splicing(head1,head2);
    //排序
    sort(head3);
    //打印
    print(head3);
    return 0;
}
list* read(list* head)
{
    list* p, * q;
    p = (list*)malloc(sizeof(list));
    scanf("%d", &(p->date));
    p->next = NULL;
    head = p;
    q = p;
    //创建链表
    while (p->date != -1)
    {
        num++;
        p = (list*)malloc(sizeof(list));
        scanf("%d", &(p->date));
        p->next = NULL;
        q->next = p;
        q = q->next;
    }
    return head;
}
list* Splicing(list* head1, list* head2)
{
    list* head1tail;
    head1tail = head1;
    while (head1tail->date != -1)
        head1tail = head1tail->next;
    head1tail->date = head2->date ;
    head1tail->next = head2->next ;
    return head1;
}
void sort(list* head)
{
    list* p, * q;
    int tmp,i;
    for (i = 0; i < num; i++)
    {
        p = head;
        q = head->next;
        while (p->next->next  != NULL)
        {
            if (p->date > q->date)
            {
                tmp = p->date;
                p->date = q->date;
                q->date = tmp;
            }
            p = p->next;
            q = q->next;
        }
   }
}
void print(list* head)
{
    list* p = head;
    int i = 0;
    while (p->next != NULL)
    {
        if (i == 0)
        {
            printf("%d", p->date);
            i++;
        }
        else
            printf(" %d", p->date);
        p = p->next;
    }
}